package com.example.sportgoods.Service.impl;

import com.example.sportgoods.domain.Shop;
import com.example.sportgoods.mapper.ShopMapper;
import com.example.sportgoods.Service.ShopService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShopServiceImpl implements ShopService{

    private static final Logger log = LoggerFactory.getLogger(ShopServiceImpl.class);

    @Autowired
    private ShopMapper shopMapper;

    public List<Shop> getShops(){
        return shopMapper.getAll();
    }

    @Override
    public List<Shop> selectAllShops() {
        return shopMapper.getAll();
    }

    public Shop selectShopById(Long id)
    {
        Shop shop = shopMapper.selectShopById(id);
        return shopMapper.selectShopById(id);
    }

    public int updateShop(Shop shop)
    {
        return shopMapper.updateShop(shop);
    }
    @Override
    public void addShop(Shop shop) {
        try {
            shopMapper.insertShop(shop);
            log.info("成功新增店铺，店铺id为 {}", shop.getId());
        } catch (Exception e) {
            log.error("新增店铺时出现异常", e);
            throw e;
        }
    }
    @Override
    public void deleteShopById(Long id) {
        try {
            shopMapper.deleteShopById(id);
            log.info("成功删除店铺，店铺id为 {}", id);
        } catch (Exception e) {
            log.error("根据店铺id删除店铺时出现异常", e);
            throw e;
        }
    }
}